# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=wasi-libc
pkgver=0.20240926
_gitrev=5ed3ec5701b58347d28a87c84ccc95f9c54b0148
pkgrel=0
pkgdesc="WASI libc implementation for WebAssembly"
url="https://github.com/WebAssembly/wasi-libc"
arch="all"
options="!check" # no testsuite
# https://github.com/WebAssembly/wasi-libc/blob/main/LICENSE
#   wasi-libc			- Apache License v2.0 WITH LLVM Exceptions AND
#				  Apache License v2.0 AND MIT
#   dlmalloc/			- CC0
#   libc-bottom-half/cloudlibc/	- BSD-2-Clause
#   libc-top-half/musl/		- MIT
license="Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT AND CC0-1.0 AND BSD-2-Clause"
makedepends="clang llvm"
source="wasi-libc-$_gitrev.tar.gz::https://github.com/WebAssembly/wasi-libc/archive/$_gitrev.tar.gz
	no-double-build.patch
	"
builddir="$srcdir"/$pkgname-$_gitrev

build() {
	# https://bugzilla.mozilla.org/show_bug.cgi?id=1773200#c4
	make CC=clang BULK_MEMORY_SOURCES=
	make CC=clang THREAD_MODEL=posix

	# new wasm targets needed by rust
	make CC=clang TARGET_TRIPLE=wasm32-wasip1
	make CC=clang TARGET_TRIPLE=wasm32-wasip1-threads THREAD_MODEL=posix
	make CC=clang TARGET_TRIPLE=wasm32-wasip2 WASI_SNAPSHOT=p2
}

package() {
	make CC=clang INSTALL_DIR="$pkgdir"/usr/share/wasi-sysroot install
}

sha512sums="
62c08f257f0002e3a24cab9e7554224249db9e685744745698aa1f76efda6ca5451b0eb6bdddcffb8c10b239f8fd345d561569a479fba5f05ec8fc3109cd4d45  wasi-libc-5ed3ec5701b58347d28a87c84ccc95f9c54b0148.tar.gz
8241854f3331e4e22756f4414afcd6cd766d48e2a1a38ad6c95903f84b6f6b718b1ed0eae2ef0fe78f2ab5c87352ffb44f1eca3ea03983173b80f72af5948651  no-double-build.patch
"
